package tests;
import tester.*;

import java.awt.Color;

import colors.*;
import geometry.*;
import draw.*;
import idraw.*;

/**
 * Copyright 2007, 2008 Viera K. Proulx
 * This program is distributed under the terms of the 
 * GNU Lesser General Public License (LGPL)
 */

/**
 * A class to demonstrate and test the use of the test harness
 * for the Canvas and Colors in the three World teachpacks.
 * 
 * @author Viera K. Proulx
 * @since 3 June 2007
 *
 */
@Example
public class WorldExamples{
  
  WorldExamples(){}
  

  /** Sample draw.Canvas data to tests the draw teachpack */
  public draw.Canvas myCanvas = new draw.Canvas(200, 300);
  public draw.Canvas secondCanvas = new draw.Canvas(200, 300);
  public draw.Canvas thirdCanvas = secondCanvas;
  public IColor myRed = new Red();
  public IColor myBlue = new Blue();

  /** Sample draw.Canvas data to tests the draw teachpack */
  public idraw.Canvas myIdrawCanvas = new idraw.Canvas(200, 300);
  public idraw.Canvas secondIdrawCanvas = new idraw.Canvas(200, 300);
  public idraw.Canvas thirdIdrawCanvas = secondIdrawCanvas;

  /** Sample adraw.Canvas data to tests the draw teachpack */
  /*
  public adraw.Canvas myAdrawCanvas = new adraw.Canvas(200, 300);
  public adraw.Canvas secondAdrawCanvas = new adraw.Canvas(200, 300);
  public adraw.Canvas thirdAdrawCanvas = secondCanvas;
  */
  @TestMethod
  public boolean testCanvas(Tester t){
    return
    // tests for the draw teachpack
    t.checkExpect(this.thirdCanvas, this.secondCanvas, "Canvas same") &&
    t.checkFail(this.myCanvas, this.secondCanvas, "Canvas different") &&
    
    // tests for the idraw teachpack
    t.checkExpect(this.thirdIdrawCanvas, this.secondIdrawCanvas, "Canvas same") &&
    t.checkFail(this.myIdrawCanvas, this.secondIdrawCanvas, "Canvas different");
    
    // tests for the adraw teachpack
    //t.checkExpect(this.thirdCanvas, this.secondCanvas, "Canvas same") &&
    //t.checkExpect(this.myCanvas, this.secondCanvas, "Canvas different");
    
  }
  
  public IColor red = new Red();
  public IColor blue = new Blue();
  
  public Color cred = new Color(255, 0, 0);
  public Color cblue = new Color(0, 0, 255);
  
  public Sampler sampler1 = new Sampler("Sampler", 2, Color.red);
  public Sampler sampler2 = new Sampler("Sampler", 2, Color.red);
  public Sampler sampler3 = new Sampler("Sampler", 2, Color.red);
  
 
  /**
   * Tests for different versions of colors - in the world teachpack,
   * vs. in <CODE>java.awt</CODE>
   * 
   * @param t the <CODE>{@link Tester Tester}</CODE> that performs the tests
   */
  @TestMethod
  public boolean testColors(Tester t){
    return
    // comparing IColor objects
    t.checkExpect(red, new Red(), "same IColor-s OK") &&

    // comparing Color objects
    t.checkExpect(cred, Color.red, "same Color-s OK") &&
    
    // comparing IColor and Color objects
    t.checkExpect(red, Color.red, "same IColor and Color - OK") &&
    
    // comparing IColor and Color objects
    t.checkExpect(Color.red, red, "same Color and IColor - OK") &&
    
    // comparing sample objects
    t.checkExpect(sampler1, sampler2, "same samplers");
  }
  
  /**
   * Tests for different versions of colors - in the world teachpack,
   * vs. in <CODE>java.awt</CODE> - the test should fail
   * 
   * @param t the <CODE>{@link Tester Tester}</CODE> that performs the tests
   */
  @TestMethod
  public boolean testColors1(Tester t){
    return  
    // comparing IColor objects
    t.checkFail(red, blue, "not same IColor-s -- fails");
  }
  
  /**
   * Tests for different versions of colors - in the world teachpack,
   * vs. in <CODE>java.awt</CODE> - the test should fail
   * 
   * @param t the <CODE>{@link Tester Tester}</CODE> that performs the tests
   */
  @TestMethod
  public boolean testColors2(Tester t){
    return  
    // comparing IColor objects
    t.checkFail(cred, cblue, "not same Color-s -- fails");
  }
  
  /**
   * Tests for different versions of colors - in the world teachpack,
   * vs. in <CODE>java.awt</CODE> - the test should fail
   * 
   * @param t the <CODE>{@link Tester Tester}</CODE> that performs the tests
   */
  @TestMethod
  public boolean testColors3(Tester t){
    return  
    // mixing IColor and Color objects
    t.checkFail(blue, cred, "not same IColor and Color - should fail");
  }
  
  /**
   * Tests for different versions of colors - in the world teachpack,
   * vs. in <CODE>java.awt</CODE> - the test should fail
   * 
   * @param t the <CODE>{@link Tester Tester}</CODE> that performs the tests
   */
  @TestMethod
  public boolean testColors4(Tester t){
    return  
 // mixing iColor and Color objects
    t.checkFail(cred, Color.blue, 
        "IColor red and Color blue - not same - should fail");
  }
  
  /**
   * Tests for different versions of colors - in the world teachpack,
   * vs. in <CODE>java.awt</CODE> - the test should fail
   * 
   * @param t the <CODE>{@link Tester Tester}</CODE> that performs the tests
   */
  @TestMethod
  public boolean testColors5(Tester t){
    return  
    // comparing sample objects
    t.checkExpect(sampler1, sampler3, "not the same samplers -- fails");
  }
}

/**
 * A class to test visibility modifier access,
 * the handling of colors, and more...
 * 
 * @author Viera K. Proulx
 * @since 30 May 2007
 */
class Sampler{

  /** the title field -- protected */
  protected String title;
  /** the length field -- private */
  private int length;
  
  /** the counter field -- static */
  public static int counter = 0;
  
  /** the color -- as defined in the java.awt */
  public Color javaColor;

  /**
   * The standard constructor
   * @param title the title of the sampler
   * @param length the length of the sampler
   * @param javaColor the Color field
   */
  public Sampler(String title, int length, Color javaColor){
    this.title = title;
    this.length = length;
    this.javaColor = javaColor;
    counter = counter + 1;
  }
  
  /**
   * A method used to test protected method invocation
   * and a return value other than boolean
   * combined with the use of static variables
   * 
   * @param that a sampler to compare with
   * @return the shorter song between this and that
   */
  private Sampler shorter(Sampler that){
    if (this.length < that.counter)
      return this;
    else
      return that;
  }
}
  
